package com.nd.android.musicboxlibrary.ui.common;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.ngds.library.downloadcenter.AppDownloadHelperImpl;

/**
 * NetStatusChangedReceiver Description: Author:walker lx Date :14-5-20
 */
public class NetStatusChangedReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (null != action && action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            Log.d("NetStatusChangedReceiver", "net status changed");
            // 获得网络连接服务
            ConnectivityManager connManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            // State state = connManager.getActiveNetworkInfo().getState();
            // 获取WIFI网络连接状态
            NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                    .getState();
            // 判断是否正在使用WIFI网络,默认wifi下继续上次下载
            if (NetworkInfo.State.CONNECTED == state) {
                AppDownloadHelperImpl.getInstance(context).start();
            }
            // 3G下给提示？
        }
    }
}
